package acm.集美大学;

import java.util.*;
import java.util.function.Function;

public class F统一命名 {
    private static Map<String, Function<String,String>> map=new HashMap<>();
    static {
        map.put("Snake",(s)->{
            char[][] split = split(s);
            StringBuilder builder=new StringBuilder();
            for (char[] str : split) {
                builder.append(str).append("_");
            }
            builder.deleteCharAt(builder.length()-1);
            return builder.toString();
        });

        map.put("Camel",(s)->{
            char[][] split = split(s);
            StringBuilder builder=new StringBuilder();
            builder.append(split[0]);
            for (int i = 1; i < split.length; i++) {
                split[i][0]-=32;
                builder.append(split[i]);
            }
            return builder.toString();
        });

        map.put("Pascal",(s)->{
            char[][] split = split(s);
            StringBuilder builder=new StringBuilder();
            for (int i = 0; i < split.length; i++) {
                split[i][0]-=32;
                builder.append(split[i]);
            }
            return builder.toString();
        });
    }
    public static char[][] split(String str){
        int len = str.length();
        List<String> list=new ArrayList<>();
        int pre=0;
        for (int i = 0; i < len; i++) {
            char c = str.charAt(i);
            if (c=='_'){
                list.add(new String(str.substring(pre,i).toLowerCase()));
                pre=i+1;
            }else if (c>='A'&&c<='Z'){
                list.add(new String(str.substring(pre,i).toLowerCase()));
                pre=i;
            }
        }
        list.add(new String(str.substring(pre,len).toLowerCase()));
        int s= list.get(0).isEmpty() ?1:0;
        int size = list.size();
        char[][] res=new char[size-s][];
        int cnt=0;
        while (s<size){
            res[cnt++]=list.get(s++).toCharArray();
        }
        return res;
    }
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n = sc.nextInt();
        String mode = sc.next();
        Function<String, String> handle = map.get(mode);
        for (int i = 0; i < n; i++) {
            String next = sc.next();
            String apply = handle.apply(next);
            System.out.println(apply);
        }
    }
}
